﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace SwormTests.IUD
{
    public class identity_pk : TestBase
    {
        public identity_pk(DbToTest db) : base(db) { }

        public class by_convention
        {
            public int id { get; set; }
            public string str { get; set; }
        }

        public class by_attribute
        {
            [Sworm.Column(IsPrimaryKey = true, IsAutoIncrement = true)]
            public int the_pk { get; set; }

            public string str { get; set; }
        }

        [Test]
        public void conventional_insert()
        {
            var r1 = new by_convention() { str = "s1" };
            Assert.AreEqual(0, r1.id);
            DB.Insert(r1);
            Assert.AreNotEqual(0, r1.id);

            var r2 = new by_convention() { str = "s2" };
            Assert.AreEqual(0, r2.id);
            DB.Insert(r2);
            Assert.AreNotEqual(0, r2.id);
            Assert.AreEqual(r1.id + 1, r2.id);
        }

        [Test]
        public void attributed_insert()
        {
            var r1 = new by_attribute() { str = "s1" };
            Assert.AreEqual(0, r1.the_pk);
            DB.Insert(r1);
            Assert.AreNotEqual(0, r1.the_pk);

            var r2 = new by_attribute() { str = "s2" };
            Assert.AreEqual(0, r2.the_pk);
            DB.Insert(r2);
            Assert.AreNotEqual(0, r2.the_pk);
            Assert.AreEqual(r1.the_pk + 1, r2.the_pk);
        }
    }
}
